﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using mitasoft.AdsShedule.Business;
using mitasoft.AdsShedule.Common;
using System.IO;

namespace mitasoft.AdsShedule
{
    public partial class MainPage : Form
    {

        #region ctor
        public MainPage()
        {
            InitializeComponent();
            this.FormClosed += new FormClosedEventHandler(MainPage_FormClosed);
            this.MdiChildActivate += new EventHandler(MainPage_MdiChildActivate);
        }

        void MainPage_MdiChildActivate(object sender, EventArgs e)
        {
            var activeForm = this.ActiveMdiChild;
            if (activeForm != null)
            {
                Form[] children = this.MdiChildren.Where(item => item.GetType() != activeForm.GetType()).ToArray();
                foreach (var form in children)
                {
                    form.Close();
                }

            }
        }
        #endregion

        #region handlers

        private void MainPage_FormClosed(object sender, FormClosedEventArgs e)
        {
            Application.Exit();
        }
        private void MainPage_Load(object sender, EventArgs e)
        {
            EnsureSettings();
            FormatTitle();



        }

        private void FormatTitle()
        {
            this.Text = string.Format("{0} - {1}", "Luna curenta", Common.AppCommon.SelectedMonthFormated);
        }

        private void button1_Click(object sender, EventArgs e)
        {

        }

        private void clientsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Forms.ManageClients manageClients = new Forms.ManageClients();
            manageClients.MdiParent = this;
            manageClients.WindowState = FormWindowState.Maximized;
            manageClients.Show();
        }
        private void adVoicesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Forms.ManageVoicesAssoc manageVoices = new Forms.ManageVoicesAssoc();
            manageVoices.MdiParent = this;
            manageVoices.WindowState = FormWindowState.Maximized;
            manageVoices.Show();
        }

        #endregion

        #region private methods
        private void EnsureSettings()
        {
            Common.AppCommon.EnsureDataFilesFolder();
        }
        #endregion

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void appoimentToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void makeAppoimentToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Forms.MakeAppoiment makeApp = new Forms.MakeAppoiment();
            makeApp.MdiParent = this;
            makeApp.WindowState = FormWindowState.Maximized;
            makeApp.Show();
        }

        private void printAppoimentToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Forms.ReportV reportV = new Forms.ReportV();
            reportV.MdiParent = this;
            reportV.WindowState = FormWindowState.Maximized;
            //reportV.ShowDialog();
            reportV.Show();
        }

        private void voicesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Forms.ManageVoices frmVoice = new Forms.ManageVoices();
            frmVoice.MdiParent = this;
            frmVoice.WindowState = FormWindowState.Maximized;
            frmVoice.Show();
        }



    }
}
